package com.geoway.adf.report.po;

import com.geoway.adf.report.excel.sheet.Sheet;
import com.vladmihalcea.hibernate.type.json.JsonType;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.*;
import java.io.Serializable;

/**
 * @Author: lzw
 * @Date: 2024/1/12 16:09
 * @Description: sheet页对象
 */
@Entity
@Table(name="adf_report_sheet")
@TypeDef(name = "jsonType", typeClass = JsonType.class)
public class SheetPO extends BaseEntity implements Serializable {

    /**
     * sheetId
     */
    @Id
    @Column(name="id")
    @GeneratedValue(generator = "simpleUUID")
    @GenericGenerator(name = "simpleUUID", strategy = "com.geoway.adf.report.jpa.SimpleUUIDGenerator")
    private String id;

    /**
     * ExcelID
     */
    @Column(name="excelId",nullable=false)
    private String excelId;

    /**
     * sheet名称
     */
    @Column(name="name")
    private String name;

    /**
     * sheet激活状态
     */
    @Column(name="status")
    private Byte status;

    /**
     * sheet下标
     */
    @Column(name="[order]")
    private Byte order;

    /**
     * sheet原始数据
     */
    @Column(name="sheet",columnDefinition = "jsonb")
    @Type(type = "jsonType")
    private Sheet sheet;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getExcelId() {
        return excelId;
    }

    public void setExcelId(String excelId) {
        this.excelId = excelId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Byte getStatus() {
        return status;
    }

    public void setStatus(Byte status) {
        this.status = status;
    }

    public Byte getOrder() {
        return order;
    }

    public void setOrder(Byte order) {
        this.order = order;
    }

    public Sheet getSheet() {
        return sheet;
    }

    public void setSheet(Sheet sheet) {
        this.sheet = sheet;
    }

    @Override
    public String toString() {
        return "SheetPO{" +
                "id='" + id + '\'' +
                ", excelId='" + excelId + '\'' +
                ", name='" + name + '\'' +
                ", status=" + status +
                ", order=" + order +
                ", sheet=" + sheet +
                "} " + super.toString();
    }

    public static SheetPO toSheetPO(Sheet sheet, String excelId){
        SheetPO sheetPO = new SheetPO();
        sheetPO.setId(sheet.getIndex());
        sheetPO.setExcelId(excelId);
        sheetPO.setName(sheet.getName());
        sheetPO.setOrder(sheet.getOrder());
        sheetPO.setStatus(sheet.getStatus());
        sheetPO.setSheet(sheet);
        return sheetPO;
    }
}
